//
//  JMTaskTVController.m
//  jiMuOperate
//
//  Created by 胡梅方 on 16/5/3.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMTaskTVController.h"
#import "JMReNameAuthTVController.h"
#import "JMCanPubStagyInfo.h"
#import "JMRelegaDemotionVController.h"
#import "JMGrabChipsVController.h"
#import "JMNickNameVController.h"
#import "JVGradeApplyVController.h"
#import "JMTaskInfo.h"
#import "JMTaskViewCell.h"

@interface JMTaskTVController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,assign)int viewY;
@property(nonatomic,strong)NSMutableArray *taskArray;
@end

@implementation JMTaskTVController
{
    int returnNum;
    UserEntity* user;
}
-(NSMutableArray*)taskArray
{


    if (_taskArray == nil) {
        _taskArray = [NSMutableArray arrayWithObjects:@"昵称设置",@"实名开户",@"等级申请",@"松果抢筹",@"保级/降级",@"发布策略",@"购买红松果",@"邀请注册", nil];
    }
    return _taskArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    HIDDENNAV(NO);
//        self.taskArray = [NSMutableArray arrayWithObjects:@"昵称设置",@"实名开户",@"等级申请",@"松果抢筹",@"保级/降级",@"发布策略",@"购买红松果",@"邀请注册", nil];
    user = [UserEntity shardUserInfo];
    if (user.nickName)
    {
        [self.taskArray removeObjectAtIndex:0];
    }
    if ([user.IsStrategyPeople  isEqual:@"0"]){
        [self.taskArray removeObject:@"发布策略"];
        [self.taskArray removeObject:@"购买红松果"];
        
    }
    if ([user.IsExtend isEqual:@"0"])
    {
        [self.taskArray removeLastObject];
    }
    if ([user.UserLevel  isEqual:@"10"]){
        [self.taskArray removeObject:@"等级申请"];
    }
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,self.viewY, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.tableView = tableView;
    [self.view addSubview:tableView];

    tableView.dataSource = self;
    tableView.delegate = self;
    self.tableView.scrollEnabled = NO;
    HIDDENNAV(NO);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
    self.tableView.tableHeaderView = view;
    self.tableView.backgroundColor = BACKCOLOR;
    self.view.backgroundColor = BACKCOLOR;
    self.navigationItem.title = @"任务";
  
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    HIDDENNAV(NO);
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    user.IsExtend = @"1";
//    if ([user.IsStrategyPeople intValue]>0) {
//        return 7;
//    }else if([user.IsExtend intValue]>0){
//        return 6;
//    }else{
//        return 5;
//    }
    return _taskArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *taskCell = @"TaskCell";
    JMTaskViewCell *cell = [tableView dequeueReusableCellWithIdentifier:taskCell];
    if (!cell) {
        cell = [[JMTaskViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:taskCell];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
\
    UIButton *cellBtn = [ARC createButtonWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40) Target:self Sel:@selector(cellBtnClick:)];
    cellBtn.tag = indexPath.row + BtnTag;
    [cell.contentView addSubview:cellBtn];

    
    UIImageView *lineImg = [[UIImageView alloc]initWithFrame:CGRectMake(0,50, 320, 1)];
    lineImg.image = [UIImage imageNamed:@"halvingline_2"];
    [cell.contentView addSubview:lineImg];
    lineImg.frame = [ToolViewAndData MyAutoLayout:lineImg];

    
    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"aut_ico_arrow"]];

    cell.nameLabel.text = self.taskArray[indexPath.row];
    if ([self.taskArray[indexPath.row] isEqual:@"昵称设置"]) {
        cellBtn.tag = BtnTag;
         cell.headImage.image = [UIImage imageNamed:@"nicknam"];
    }else if ([self.taskArray[indexPath.row] isEqual:@"实名开户"]) {
        cell.headImage.image = [UIImage imageNamed:@"aut_ico_wallet"];
        cellBtn.tag = BtnTag*2;
    }else if([self.taskArray[indexPath.row] isEqual:@"等级申请"])
    {
        cell.headImage.image = [UIImage imageNamed:@"aut_ico_rank"];
        cellBtn.tag = BtnTag*3;
    }else if([self.taskArray[indexPath.row] isEqual:@"松果抢筹"])
    {
        cell.headImage.image = [UIImage imageNamed:@"aut_ico_Rob-to-raise"];
        cellBtn.tag = BtnTag*4;
    }else if([self.taskArray[indexPath.row] isEqual:@"保级/降级"])
    {
        cell.headImage.image = [UIImage imageNamed:@"aut_ico_relegation"];
        cellBtn.tag = BtnTag*5;
    }


    
    
    
//    if ([user.IsStrategyPeople intValue]>0) {
//        switch (indexPath.row) {
//            case 0:
//                describImg.image = [UIImage imageNamed:@"nicknam"];
//                descibLabel.text = @"昵称设置";
//                if (user.nickName) {
//                    cell.backgroundColor = BACKCOLOR;
//                }
//                break;
//            case 1:
//                describImg.image = [UIImage imageNamed:@"aut_ico_wallet"];
//                descibLabel.text = @"实名开户";
//                break;
//            case 2:
//                describImg.image = [UIImage imageNamed:@"aut_ico_rank"];
//                descibLabel.text = @"等级申请";
//                break;
//            case 3:
//                describImg.image = [UIImage imageNamed:@"aut_ico_Rob-to-raise"];
//                descibLabel.text = @"松果抢筹";
//                break;
//            case 4:
//                describImg.image = [UIImage imageNamed:@"aut_ico_relegation"];
//                descibLabel.text = @"保级/降级";
//                break;
//            case 5:
//                describImg.image = [UIImage imageNamed:@"aut_ico_Release-strategy"];
//                descibLabel.text = @"发布策略";
//                break;
//            case 6:
//                describImg.image = [UIImage imageNamed:@"aut_ico_Release-strategy"];
//                descibLabel.text = @"购买红松果";
//                break;
//        }
//
//    }else if([user.IsExtend intValue]>0){
//        switch (indexPath.row) {
//            case 0:
//                describImg.image = [UIImage imageNamed:@"nicknam"];
//                descibLabel.text = @"昵称设置";
//                break;
//            case 1:
//                describImg.image = [UIImage imageNamed:@"aut_ico_wallet"];
//                descibLabel.text = @"实名开户";
//                break;
//            case 2:
//                describImg.image = [UIImage imageNamed:@"aut_ico_rank"];
//                descibLabel.text = @"等级申请";
//                break;
//            case 3:
//                describImg.image = [UIImage imageNamed:@"aut_ico_Rob-to-raise"];
//                descibLabel.text = @"松果抢筹";
//                break;
//            case 4:
//                describImg.image = [UIImage imageNamed:@"aut_ico_relegation"];
//                descibLabel.text = @"保级/降级";
//                break;
//             case 5:
//                describImg.image = [UIImage imageNamed:@"aut_ico_relegation"];
//                descibLabel.text = @"邀请注册";
//                break;
//
//        }
//
//     
//    }else{
//        switch (indexPath.row) {
//            case 0:
//                describImg.image = [UIImage imageNamed:@"nicknam"];
//                descibLabel.text = @"昵称设置";
//                break;
//            case 1:
//                describImg.image = [UIImage imageNamed:@"aut_ico_wallet"];
//                descibLabel.text = @"实名开户";
//                break;
//            case 2:
//                describImg.image = [UIImage imageNamed:@"aut_ico_rank"];
//                descibLabel.text = @"等级申请";
//                break;
//            case 3:
//                describImg.image = [UIImage imageNamed:@"aut_ico_Rob-to-raise"];
//                descibLabel.text = @"松果抢筹";
//                break;
//            case 4:
//                describImg.image = [UIImage imageNamed:@"aut_ico_relegation"];
//                descibLabel.text = @"保级/降级";
//                break;
//                
//                
//        }
//
//    
//    }
    
     
    
    
    [cell.contentView addSubview:[ARC createImageViewLineWithHeigt:1]];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return CELLHIGHT;
}

-(void)cellBtnClick:(UIButton*)btn
{
    switch (btn.tag) {
        case SetNickNameBtn:{
            JMNickNameVController *nickNameVc = [[JMNickNameVController alloc]init];
            [self.navigationController pushViewController:nickNameVc animated:YES];
            break;
        }
        case ReNameAuthBtn:{
            JMReNameAuthTVController *reNameAuthVC = [[JMReNameAuthTVController alloc]init];
            [self.navigationController pushViewController:reNameAuthVC animated:YES];
            break;
        }
        case GradeApplyBtn:{
       
            JVGradeApplyVController *gradeApplyVC = [[JVGradeApplyVController alloc]init];
            [self.navigationController pushViewController:gradeApplyVC animated:YES];
            break;
        }
        case PineNumRushBtn:{
            JMGrabChipsVController *grabChipVc = [[JMGrabChipsVController alloc]init];
            [self.navigationController pushViewController:grabChipVc animated:YES];
            break;
        }

        case RelegationBtn:{
            NSLog(@"index:6");
            JMRelegaDemotionVController *reDemotionVc = [[JMRelegaDemotionVController alloc]init];
            [self.navigationController pushViewController:reDemotionVc animated:YES];
            break;
        }
        case ReleaseStageBtn:{
            if ([user.IsStrategyPeople intValue]>0) {
                NSLog(@"gfhdfgj");
            }else{
            }
//            NSString *token = [UserEntity shardUserInfo].access_token;
//            [self requestCanPubStrategyWithToken:token];
            break;
        }
        case BuyRedPineBtn:{
            break;
        }
            
        default:
            break;
    }
}

@end
